<?php

namespace app\admin\model;

use think\Model;

class Meun extends Model
{
    protected $name = 'car_admin_meun'; //表名      默认类型
    protected $autoWriteTimestamp = true;
    protected $dateFormat = 'Y/m/d H:i:s';
    // 定义时间戳字段名
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    public function children()
    {
        $list = $this->hasMany(Meun::class,  'parentId', 'id')->order(['sort'=>'desc','create_at'=>'desc']);
        return $list;
    }

    public function childrenRouter()
    {
        $list = $this->hasMany(Meun::class,  'parentId', 'id')->where('type', 0)->order(['sort'=>'desc','create_at'=>'desc']);
        return $list;
    }

    public function childrenRouterAll()
    {
        $list = $this->hasMany(Meun::class,  'parentId', 'id')->where('type', 0)->order(['sort'=>'desc','create_at'=>'desc']);
        return $list;
    }

    public function setMetaAttr($value)
    {
        return json_encode($value);
    }

    public function getMetaAttr($value)
    {
        return json_decode($value);
    }

    public function setShowNextAttr($value)
    {
        return $value ? 1 : 0;
    }

    public function getShowNextAttr($value)
    {
        return $value == 1;
    }

}